import { _decorator, Component, input, Input, Node, Sprite, SpriteFrame } from 'cc';
import { CardData } from './CardData';
import { CardEnum } from './CardEnum';
const { ccclass, property } = _decorator;

@ccclass('Card')
export class Card extends Component {

    @property(Sprite)
    public sp : Sprite;
    
    @property(SpriteFrame)
    public shield : SpriteFrame;

    
    @property(SpriteFrame)
    public boom : SpriteFrame;

    @property(SpriteFrame)
    public reload : SpriteFrame;
    
    @property(SpriteFrame)
    public shoot : SpriteFrame;


    public cardData :CardData;
    private onClickHandler : Function;
    private clickObj :any;

    start() {
        

    }

    update(deltaTime: number) {
        
    }

    public upCardData(c : CardData)
    {
        this.cardData = c;
        this.upDisplay();
    }

    public setData(c : CardData,f : Function,o:any)
    {
        this.onClickHandler = f;
        this.clickObj = o;
        this.upCardData(c);
    }


    private upDisplay()
    {
        switch(this.cardData.cardValue)
        {
            case CardEnum.boom:
                this.sp.spriteFrame = this.boom;
                break;

            case CardEnum.shield:
                this.sp.spriteFrame = this.shield;
                break;

            case CardEnum.reload:
                this.sp.spriteFrame = this.reload;
                break;

            case CardEnum.shoot:
                this.sp.spriteFrame = this.shoot;
                break;
        }
    }



}

